package com.opo5.logisticsmanagement.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.opo5.logisticsmanagement.dao.DepotTransferRecordDao;
import com.opo5.logisticsmanagement.domain.DTFRParam;
import com.opo5.logisticsmanagement.domain.DepotTransferRecord;
import com.opo5.logisticsmanagement.Vo.PageVo;
import com.opo5.logisticsmanagement.service.DepotTransferRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DepotTransferRecordServiceImpl extends ServiceImpl<DepotTransferRecordDao, DepotTransferRecord> implements DepotTransferRecordService {

    @Autowired
    private DepotTransferRecordDao depotTransferRecordDao;

    @Override
    public PageVo getMaterialTransferRecord(Integer currentPage, Integer pageSize, DTFRParam dtfrParam) {

        System.out.println(currentPage);
        System.out.println(pageSize);
        System.out.println(dtfrParam);

        if(currentPage<=0){
            currentPage=1;
        }

        Integer pageBegin=(currentPage-1)*pageSize;

        System.out.println(pageBegin);

        List<DepotTransferRecord> recordList = depotTransferRecordDao.getMaterialTransferRecord(pageBegin, pageSize, dtfrParam);

        System.out.println(recordList);

        Integer total = depotTransferRecordDao.getTotal(dtfrParam);

        System.out.println(total);

        Integer pages=(total-1)/pageSize+1;

        PageVo recordPage=new PageVo();

        recordPage.setRecords(recordList);
        recordPage.setTotal(total);
        recordPage.setPages(pages);
        recordPage.setCurrent(currentPage);
        recordPage.setSize(pageSize);

        return recordPage;
    }


//    @Override
//    public PageVo getMaterialTransferRecord(Integer currentPage, Integer pageSize, DTFRParam dtfrParam) {
//        if(currentPage<=0){
//            currentPage=1;
//        }
//
//        Integer pageBegin=(currentPage-1)*pageSize;
//
//        List<DepotTransferRecord> recordList = depotTransferRecordDao. locatorName, materialName);
//
//        Integer total = depotTransferRecordDao.getTotal(depotName, locatorName, materialName);
//
//        Integer pages=(total-1)/pageSize+1;
//
//        PageVo recordPage=new PageVo();
//
//        recordPage.setRecords(recordList);
//        recordPage.setTotal(total);
//        recordPage.setPages(pages);
//        recordPage.setCurrent(currentPage);
//        recordPage.setSize(pageSize);
//
//        return recordPage;
//    }
}
